home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / bc_pas_1.zip / MEMORY.ASM < prev    next >
Assembly Source File  |  1992-10-19  |  2KB  |  125 lines

  1.  
  2.         page    64,131
  3.     Title    MEM.ASM -- Memory Allocation Routines
  4.  
  5. ;   /*\
  6. ;---|*|------------====< MEM.ASM >====------------
  7. ;---|*|
  8. ;---|*| Copyright (c) 1991, 1992 Media Vision, Inc. All rights reserved.
  9. ;---|*|
  10. ;   \*/
  11.  
  12.         .xlist
  13.     include model.inc
  14.     include masm.inc
  15.         include common.inc
  16.     .list
  17.  
  18. ;
  19. ;---------------------------========================---------------------------
  20. ;---------------------------====< DATA SECTION >====---------------------------
  21. ;---------------------------========================---------------------------
  22. ;
  23.  
  24. if MODELSIZE eq 0
  25.     .code
  26. else
  27.     .data
  28. endif
  29.  
  30. ;
  31. ;---------------------------========================---------------------------
  32. ;---------------------------====< CODE SECTION >====---------------------------
  33. ;---------------------------========================---------------------------
  34. ;
  35.         .code
  36.  
  37. ;   /*\
  38. ;---|*|------------====< _memmalloc ( long ) >====------------
  39. ;---|*|
  40. ;---|*| Allocate a block of memory from DOS
  41. ;---|*|
  42. ;---|*| Entry Conditions:
  43. ;---|*|     dParm1 - is the size in bytes
  44. ;---|*|
  45. ;---|*| Exit Conditions:
  46. ;---|*|     dword is the block pointer, else 0 if in error
  47. ;---|*|
  48. ;   \*/
  49.  
  50.     public    _memmalloc
  51. _memmalloc    proc
  52.     push    bp
  53.     mov    bp,sp
  54. ;
  55. ; get the # of paragraphs into BX
  56. ;
  57.     mov    bx,dParm1+0
  58.     mov    dx,dParm1+2
  59.     mov    cl,4
  60.     shr    bx,cl
  61.     mov    cl,12
  62.     shl    dx,cl
  63.     add    bx,dx            ; bx = hi order 16 bits out of 24 bits
  64.     inc    bx            ; get one more 16 byte block
  65. ;
  66. ; call DOS for a memory block
  67. ;
  68.     mov    ah,48h
  69.     int    21h
  70. ;
  71. ; carry is set if in error.
  72. ;
  73.         cmc                             ; set carry if no error
  74.     sbb    bx,bx
  75.     and    ax,bx            ; ax = 0 if in error, else a segment
  76.     sub    dx,dx
  77.     xchg    ax,dx            ; dx:ax holds the pointer
  78.  
  79.     pop    bp
  80.     ret
  81.  
  82. _memmalloc    endp
  83.  
  84.  
  85. ;   /*\
  86. ;---|*|------------====< _memfree ( void far * ) >====------------
  87. ;---|*|
  88. ;---|*| Releases the allocated block of memory from DOS
  89. ;---|*|
  90. ;---|*| Entry Conditions:
  91. ;---|*|     dParm1 - is the pointer to the block
  92. ;---|*|
  93. ;---|*| Exit Conditions:
  94. ;---|*|     None
  95. ;---|*|
  96. ;   \*/
  97.  
  98.     public    _memfree
  99. _memfree    proc
  100.     push    bp
  101.     mov    bp,sp
  102.     push    es
  103. ;
  104. ; get the # of paragraphs into BX
  105. ;
  106.     mov    es,dParm1+2
  107. ;
  108. ; just do it...
  109. ;
  110.     mov    ah,49h
  111.     int    21h
  112.  
  113.     pop    es
  114.         pop     bp
  115.     ret
  116.  
  117. _memfree    endp
  118.  
  119. ;   /*\
  120. ;---|*| end of MEM.ASM
  121. ;   \*/
  122.  
  123.         end
  124.  
  125.